<?php

class SiteController extends FrontendController{
	public function actions()
	{
		return array(
			// captcha action renders the CAPTCHA image displayed on the contact page
			'captcha'=>array(
				'class'=>'CCaptchaAction',
				'backColor'=>0xFFFFFF,
			),
			// page action renders "static" pages stored under 'protected/views/site/pages'
			// They can be accessed via: index.php?r=site/page&view=FileName
			'page'=>array(
				'class'=>'CViewAction',
			),
		);
	}

	public function actionIndex(){
		// $product = new Product();
		// $criteria = new CDbCriteria();
  //       $criteria->select = 't.*';
  //       $criteria->with= 'category';
  //       //$criteria->with= 'subcategory';
  //       //$criteria->with= 'brand';
  //       //$criteria->with= 'genre';
  //       $criteria->join= 'LEFT JOIN Categories c ON t.CategoryId = c.CategoryId';
  //       $criteria->join= 'LEFT JOIN SubCategories s ON t.SubCategoryId = s.SubCateId';
  //       $criteria->join= 'LEFT JOIN Brands b ON t.BrANDId = b.BrANDId';
  //       $criteria->join= 'LEFT JOIN Genres g ON t.GenreId = g.GenreId';
  //       $criteria->limit = '3';
  //       $criteria->order = 't.CreateDate DESC';
  //       $criteria->condition = 't.Status ="1" AND category.Status = "1"';// AND subcategory.Status= :pStatus';// AND brand.Status=:pStatus AND genre.Status=:pStatus';

  //       $data = $product->findAll($criteria);
		// $this->render('index',array(
		// 	'data' => $data));
		$slidemodel = new Slide();//::model()->findAllByAttributes(array('Status' => '1'));
		$sl = new CDbCriteria();
		$sl->select = 't.*';
		$sl->with = 'content';
		$sl->join = //'LEFT JOIN Galleries g ON g.GalleryId = t.GalleryId '.
					'JOIN Slides s on s.ContentId = t.ContentId';
		//$sl->condition = 't.GalleryId =:slide';
		//$sl->params = ':slide = s.GalleryId';
		$slide = $slidemodel->findAll($sl);
		$category = new SubCategory();
		$criteria = new CDbCriteria();
        $criteria->select = 't.*';
        $criteria->with = 'product';
        $criteria->join = 'LEFT JOIN Categories c ON c.CategoryId = t.CategoryId ';
        					//'LEFT JOIN Products p ON p.SubCategoryId = t.SubCateId ' .
        					//'LEFT JOIN Galleries g ON g.GalleryId = p.GalleryId '.
        					//'LEFT JOIN Items i ON i.GalleryId = g.GalleryId';
        $criteria->limit = '3';
        $criteria->order = 't.CreateDate DESC';
        $criteria->condition = 't.Status ="1"';// and p.Status="1" and i.Thumb_nails="1"';
        $data = $category->findAll($criteria);
		$this->render('index',array(
			'data' => $data,
			'slide' => $slide
		));
	}


	public function actionContent(){
		$menu = Menu::model()->findByAttributes(array(
			'MenuNameRewrite' => $_GET['id'],
			'GroupMenu' => 0
		));
		if(!isset($menu)){
			$submenu = SubMenu::model()->findByAttributes(array(
				'SubMenuNameRewrite' => $_GET['id']));
		}
		$content = new Content();
		$criteria = new CDbCriteria();
		$criteria->select = 't.*';
		if(isset($menu)){
			$criteria->with = 'menu';
			$criteria->join = 'JOIN Menus m ON m.ContentId=t.ContentId';
			$criteria->condition = 'm.MenuNameRewrite="'.$_GET['id'].'"';
		}
		else if(isset($submenu)){
			$criteria->with = 'submenu';
			$criteria->join = 'JOIN SubMenus s ON s.ContentId=t.ContentId';
			$criteria->condition = 's.SubMenuNameRewrite="'.$_GET['id'].'"';
		}
		$data = $content->findAll($criteria);
		$this->render('content',array('data'=>$data));
	}

	public function actionFooter(){
		$menu = Menu::model()->findByAttributes(array(
			'MenuNameRewrite' => $_GET['id'],
			'GroupMenu' => 1
		));
		if(!isset($menu))
			$submenu = SubMenu::model()->findByAttributes(array('SubMenuNameRewrite' => $_GET['id']));
		$content = new Content();
		$criteria = new CDbCriteria();
		$criteria->select = 't.*';
		if(isset($menu)){
			$criteria->with = 'menu';
			$criteria->join = 'JOIN Menus m ON m.ContentId=t.ContentId';
			$criteria->condition = 'm.MenuNameRewrite="'.$_GET['id'].'"';
		}
		else if(isset($submenu)){
			$criteria->with = 'submenu';
			$criteria->join = 'JOIN SubMenus s ON s.ContentId=t.ContentId';
			$criteria->condition = 's.SubMenuNameRewrite="'.$_GET['id'].'"';
		}
		$data = $content->findAll($criteria);
		$this->render('content',array('data'=>$data));
	}
}